using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.SqlClient;

namespace Report.PhieuD
{
    public partial class UcD106 : DevExpress.XtraEditors.XtraUserControl
    {
        public UcD106()
        {
            InitializeComponent();
        }

        private void UcD106_Load(object sender, EventArgs e)
        {
            DataTable dtD106 = new DsReportX.Table7ColDataTable();
            dtD106 = CalculateData(dtD106);
            gridControlA.DataSource = dtD106;
        }

        DataTable CalculateData(DataTable dt)
        {
            SqlConnection con = new SqlConnection(GeneralLibs.LocalSettings.ConnectString);
            SqlCommand cmd = con.CreateCommand();
            SqlDataAdapter da = new SqlDataAdapter();
            try
            {
                con.Open();
                cmd.CommandText = "SELECT * FROM ( \n"+
                                "SELECT  COUNT(C.CauTraLoiFIX1) Number1 \n"+
                                "FROM Phieu B INNER JOIN ChiTietPhieu C ON B.ID = C.PhieuID \n"+
                                "WHERE B.LoaiPhieu = 'PhieuD' AND C.MaCau = 17 AND C.CauTraLoiFIX1 = 1 \n"+
                                ") CoToChuc , ( \n"+
                                "SELECT  COUNT(C.CauTraLoiFIX1) Number2 \n"+
                                "FROM Phieu B INNER JOIN ChiTietPhieu C ON B.ID = C.PhieuID \n"+
                                "WHERE B.LoaiPhieu = 'PhieuD' AND C.MaCau = 17 AND C.CauTraLoiFIX1 = 2 \n"+
                                ") KhongToChuc ,( \n"+
                                "SELECT  SUM(Number1) Number3, SUM(Number2)Number4 \n"+
                                "FROM Phieu_DangBang A INNER JOIN Phieu B ON A.PhieuID = B.ID   \n"+
                                "WHERE B.LoaiPhieu = 'PhieuD' AND A.MaCau = 18  \n" +
                                ") KinhPhi";

                da.SelectCommand = cmd;
                da.Fill(dt);

                return dt;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return null;
            }
            finally
            {
                con.Close();
            }
        }
    }
}
